package org.gesplan.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author David
 */
@Entity
@Table(name = "building")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Building.findAll", query = "SELECT b FROM Building b"),
    @NamedQuery(name = "Building.findById", query = "SELECT b FROM Building b WHERE b.id = :id"),
    @NamedQuery(name = "Building.findByDescription", query = "SELECT b FROM Building b WHERE b.description = :description")
})
public class Building implements Serializable {
    @Column(name = "level")
    private Short level;
    @OneToMany(mappedBy = "parentId")
    private Collection<Building> buildingCollection;
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @ManyToOne
    private Building parentId;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private String id;
    @Column(name = "description")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "buildingId")
    private Collection<MaterialBuilding> materialBuildingCollection;


    public Building() { }


    public Building(String id) {
        this.id = id;
    }


    public String getId() {
        return id;
    }


    public void setId(String id) {
        this.id = id;
    }


    public String getDescription() {
        return description;
    }


    public void setDescription(String description) {
        this.description = description;
    }


    @XmlTransient
    public Collection<MaterialBuilding> getMaterialBuildingCollection() {
        return materialBuildingCollection;
    }


    public void setMaterialBuildingCollection(Collection<MaterialBuilding> materialBuildingCollection) {
        this.materialBuildingCollection = materialBuildingCollection;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }


    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Building)) {
            return false;
        }
        Building other = (Building) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }


    @Override
    public String toString() {
        return description;
    }


    public Short getLevel() {
        return level;
    }


    public void setLevel(Short level) {
        this.level = level;
    }


    @XmlTransient
    public Collection<Building> getBuildingCollection() {
        return buildingCollection;
    }


    public void setBuildingCollection(Collection<Building> buildingCollection) {
        this.buildingCollection = buildingCollection;
    }


    public Building getParentId() {
        return parentId;
    }


    public void setParentId(Building parentId) {
        this.parentId = parentId;
    }
    
    
}